import pygame

class SettingsMenu:
    def __init__(self, screen, config):
        self.screen = screen
        self.config = config
        self.font = pygame.font.Font(self.config.font_path, 36)
        self.options = ["继续游戏", "小球速度", "退出游戏", "暂停游戏", "返回开始界面"]
        self.selected_option = 0

    def draw(self):
        self.screen.fill(self.config.colors['black'])
        for i, option in enumerate(self.options):
            color = self.config.colors['white'] if i != self.selected_option else self.config.colors['red']
            option_text = self.font.render(option, True, color)
            self.screen.blit(option_text, (self.config.screen_width // 2 - 100, 200 + i * 60))
        pygame.display.flip()

    def handle_events(self):
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    self.selected_option = (self.selected_option - 1) % len(self.options)
                elif event.key == pygame.K_DOWN:
                    self.selected_option = (self.selected_option + 1) % len(self.options)
                elif event.key == pygame.K_RETURN:
                    return self.selected_option
            # 添加鼠标点击事件处理
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_pos = pygame.mouse.get_pos()
                for i, _ in enumerate(self.options):
                    option_rect = pygame.Rect(
                        self.config.screen_width // 2 - 100,
                        200 + i * 60,
                        200,
                        50
                    )
                    if option_rect.collidepoint(mouse_pos):
                        return i
        return -1
